package com.umeng.analytics.pro;

import android.text.TextUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class bu {
    public static int a;

    public bu() {

    }

    public static byte[] a(byte[] arg6) throws IOException {
        ByteArrayOutputStream v1_1 = null;
        byte[] v0 = null;
        if (arg6 != null && arg6.length > 0) {
            Deflater v2 = new Deflater();
            v2.setInput(arg6);
            v2.finish();
            byte[] v3 = new byte[8192];
            bu.a = 0;
            try {
                v1_1 = new ByteArrayOutputStream();
                while (!v2.finished()) {
                    int v0_2 = v2.deflate(v3);
                    bu.a += v0_2;
                    v1_1.write(v3, 0, v0_2);
                }
                v2.end();
                v1_1.close();
                return v1_1.toByteArray();
            } catch (Throwable throwable) {

            } finally {
                if (v1_1 != null) {
                    v1_1.close();
                }
            }
        }

        return v0;
    }

    public static String a(byte[] arg2, String arg3) throws UnsupportedEncodingException, DataFormatException {
        byte[] v1 = bu.b(arg2);
        String v0 = v1 != null ? new String(v1, arg3) : null;
        return v0;
    }

    public static byte[] a(String arg1, String arg2) throws IOException {
        byte[] v0 = TextUtils.isEmpty(((CharSequence) arg1)) ? null : bu.a(arg1.getBytes(arg2));
        return v0;
    }

    public static byte[] b(byte[] arg5) throws UnsupportedEncodingException, DataFormatException {
        byte[] v0_1;
        int v0 = 0;
        if (arg5 == null || arg5.length == 0) {
            v0_1 = null;
        } else {
            Inflater v1 = new Inflater();
            v1.setInput(arg5, 0, arg5.length);
            ByteArrayOutputStream v2 = new ByteArrayOutputStream();
            byte[] v3 = new byte[1024];
            while (!v1.needsInput()) {
                int v4 = v1.inflate(v3);
                v2.write(v3, v0, v4);
                v0 += v4;
            }

            v1.end();
            v0_1 = v2.toByteArray();
        }

        return v0_1;
    }
}

